package com.woniuxy.classteacher.controller;

import com.woniuxy.classteacher.service.TeacherService;
import com.woniuxy.commons.entity.ResponseEntity;
import com.woniuxy.commons.entity.wyh.TeacherInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Auther: 牟强
 * @Date: 2020/8/1/001 10:03
 * @Description: 班主任个人中心
 */
@RestController
public class PersonalCenterController {
    @Autowired
    private TeacherService teacherService;

    /**
     * @Author: 牟强
     * @Date: 2020/8/5/005 16:16
     * @Description: 改变密码
     * @Param: [originPwd, newPwd, affirmPwd, rId]
     * @return: com.woniuxy.commons.entity.ResponseEntity<java.lang.Void>
     */
    @PostMapping("/alterPwd")
    public ResponseEntity<Void> alterPassword(String originPwd, String newPwd, String code, String affirmPwd, Integer rId) {
        System.out.println(originPwd);
        System.out.println(newPwd);
        System.out.println(affirmPwd);
        System.out.println(rId);
        System.out.println(code);
        ResponseEntity<Void> responseEntity = new ResponseEntity<>();
        teacherService.alterTeacherPwd(originPwd, newPwd, affirmPwd, code, rId);
        responseEntity.setCode(ResponseEntity.SUCCESS);
        return responseEntity;
    }

    /**
     * @Author: 牟强
     * @Date: 2020/8/5/005 16:17
     * @Description: 发送手机验证码
     * @Param: [teacherId]
     * @return: com.woniuxy.commons.entity.ResponseEntity<java.lang.Void>
     */
    @PostMapping("/sendCode")
    public ResponseEntity<Void> sendCode(Integer teacherId) {
        ResponseEntity<Void> responseEntity = new ResponseEntity<>();
        teacherService.sendAuthCode(teacherId);
        responseEntity.setCode(ResponseEntity.SUCCESS);
        return responseEntity;
    }

    /**
     * @Author: 牟强
     * @Date: 2020/8/5/005 16:17
     * @Description: 初始化修改密码界面数据
     * @Param: [request]
     * @return: com.woniuxy.commons.entity.ResponseEntity<com.woniuxy.commons.entity.wyh.TeacherInfo>
     */
    @GetMapping("/initPwd")
    public ResponseEntity<TeacherInfo> initUpdatePwd(HttpServletRequest request) {
        ResponseEntity<TeacherInfo> responseEntity = new ResponseEntity<>();
        String refreshToken = request.getHeader("refreshToken");
        TeacherInfo teacherInfo = teacherService.initUptatePwd(refreshToken);
        responseEntity.setData(teacherInfo);
        responseEntity.setCode(ResponseEntity.SUCCESS);
        return responseEntity;
    }
}
